
package thinkinginjava.concurrency;

/**
 * Demonstrate various method to create a thread
 * @author qinchong
 *
 */
public class ThreadVariations {

    public static void main(String[] args) {

    }

}

class InnerThread1 {
    private int countDown = 5;
    private Inner inner;

    public InnerThread1(String name) {
        this.inner = new Inner(name);
    }

    private class Inner extends Thread {

        public Inner(String name) {
            super(name);
            start();
        }

        @Override
        public void run() {
            try {
                while (true) {
                    System.out.println(this);
                    if (--countDown == 0)
                        return;
                    sleep(10);
                }
            } catch (InterruptedException e) {
                print("Interrupted");
            }

        }

        @Override
        public String toString() {
            return this.getName() + "::" + countDown;
        }

        private void print(String string) {
            System.out.println(string);
        }

    }
}
